//
//  ModifyNameViewController.swift
//  SwiftOfXiaoShouJia
//
//  Created by zhenjingxiong on 2018/9/7.
//  Copyright © 2018年 镇景雄. All rights reserved.
//

import UIKit

//定义闭包类型（特定的函数类型函数类型）
typealias InputClosureType = (String) -> Void

class ModifyNameViewController: BaseViewController {

    //接收上个页面传过来的闭包块
    var backClosure: InputClosureType?
    var getValue:((Bool) -> Void)?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "修改姓名"
        self.view.backgroundColor = UIColor.withHex(hexString: "#eeeeee")
        
        self.view.addSubview(self.whiteView)
        self.whiteView.snp.makeConstraints { (make) in
            make.left.right.equalTo(self.view)
            make.top.equalTo(20)
            make.height.equalTo(50)
        }
        
        self.whiteView.addSubview(self.nameTextField)
        self.nameTextField.snp.makeConstraints { (make) in
            make.left.equalTo(20)
            make.top.bottom.right.equalTo(self.whiteView)
        }
        
        self.view.addSubview(self.saveButton)
        self.saveButton.snp.makeConstraints { (make) in
            make.left.equalTo(20)
            make.top.equalTo(self.whiteView.snp.bottom).offset(20)
            make.right.equalTo(self.view.snp.right).offset(-20)
            make.height.equalTo(40)
        }
        
        self.getValue!(true)
        
        
    }
    
    
    lazy var whiteView: UIView = {
        let whiteView = UIView.init()
        whiteView.backgroundColor = UIColor.white
        return whiteView
    }()

    
    lazy var nameTextField: UITextField = {
        let nameTextField = UITextField.init()
        nameTextField.text = "镇景雄"
        return nameTextField
    }()
    
    lazy var saveButton: UIButton = {
        let saveButton = UIButton.init()
        saveButton.backgroundColor = UIColor.red
        saveButton.setTitle("保存", for: UIControlState.normal)
        saveButton.setTitleColor(UIColor.white, for: UIControlState.normal)
        saveButton.layerWithView(color: UIColor.clear, WithRadius: 5, WithBorder: 1)
        saveButton.addTarget(self, action:#selector(clickSaveButton), for: UIControlEvents.touchUpInside)
        return saveButton
    }()
    
    @objc func clickSaveButton() {
        self.backClosure!(self.nameTextField.text!)
        self.navigationController?.popViewController(animated: true)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
